Skip to content

Add --workspace-sboms flag for workspace SBOMs#870

Open
salim-runsafe wants to merge 1 commit into
CycloneDX:mainfrom
runsafesecurity:workspace-sboms-flag
Open

Add --workspace-sboms flag for workspace SBOMs#870
salim-runsafe wants to merge 1 commit into
CycloneDX:mainfrom
runsafesecurity:workspace-sboms-flag

Conversation

@salim-runsafe

Copy link
Copy Markdown

When cargo cyclonedx runs against a rust workspace, it currently emits an SBOM for every workspace member. Some workflows only need the SBOM for the crate being built from a specific manifest.

Add --workspace-sboms with values all (default) and manifest-only. The default preserves existing behavior. manifest-only limits output to the manifest from --manifest-path or the current directory.

Return a clear error when manifest-only is used with a virtual workspace root manifest that does not match any member crate.

We've been using a fork of this repo with these changes (without the CLI flag) for a while now without issue and wanted to bring the feature upstream.

I wasn't sure if it is appropriate to fill out the CHANGELOG.md with an Unreleased section or not and can revert that if needed.

When cargo cyclonedx runs against a workspace, it currently emits
an SBOM for every workspace member. Some CI flows only need the
SBOM for the crate being built from a specific manifest.

Add --workspace-sboms with values all (default) and manifest-only.
The default preserves existing behavior. manifest-only limits output
to the manifest from --manifest-path or the current directory.

Return a clear error when manifest-only is used with a virtual
workspace root manifest that does not match any member crate.

Signed-off-by: Salim Blume <salim@runsafesecurity.com>
@salim-runsafe salim-runsafe requested a review from a team as a code owner June 10, 2026 23:15
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 34 complexity · 4 duplication

Metric Results
Complexity 34
Duplication 4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@Shnatsel

Copy link
Copy Markdown
Contributor

Just to make sure I understand this correctly: you want to emit a SBOM for only a single specific crate from the workspace, right?

Why are the other crates in the workspace an issue?

@salim-runsafe

Copy link
Copy Markdown
Author

Our use case is that we identify Cargo.tomls first and then iterate over them while specifying --override-filename. This allows us to identify the generated SBOMs amongst other files in a repo with certainty.

With the current upstream behavior this iteration generates the same SBOMs multiple times, once for each crate in the workspace.

Another solution to this problem would be if we could format the output of the command to something structured. Then we could parse the list of generated SBOMs and retrieve them.

@Shnatsel

Copy link
Copy Markdown
Contributor

Ah, it's the "match SBOM to the crate" problem.

Can we write the manifest path (path to Cargo.toml) into the SBOM file? Does that help?

@salim-runsafe

Copy link
Copy Markdown
Author

We would still need to be able to know which SBOMs were generated in a structured way, otherwise we're hunting JSON files for that manifest path to try and find a match.

We also need to account for monorepos with multiple unconnected cargo workspaces within them. Today in our fork we can search an entire directory for all Cargo.tomls and then generate SBOMs 1:1 with those tomls and know what we generated because we're specifying the filename with --override-filename. The workspaces end up becoming irrelevant to our purposes, which is nice because we don't need to have any special logic for them. We also don't have to worry about side effects generating files we then need to try and sift (syft?!) through to locate the correct SBOMs.

If we were to rely on the current upstream behavior we would end up having to come up with some clever parsing to distinguish workspaces from one another, then generate SBOMs per workspace, then identify the generated SBOMs and map them to each Cargo.toml which they describe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants